package com.example.streamsqlpark.base.exception;

import com.example.streamsqlpark.base.domain.ResponseCode;

import java.util.Objects;

/**
 * @author voloiono
 * @date 2024/4/17 11:50
 */
public class ApiAlterException extends AbstructApiException{

    public ApiAlterException(String msg){
        super(msg, ResponseCode.CODE_FAIL_ALERT);
    }

    public ApiAlterException(Throwable cause){
        super(cause,ResponseCode.CODE_FAIL_ALERT);
    }

    public ApiAlterException(String msg,Throwable cause) {
        super(msg, cause, ResponseCode.CODE_FAIL_ALERT);
    }

    public static void throwIfNull(Object object,String errorMsg){
        if (Objects.isNull(object)){
            throw new ApiAlterException(errorMsg);
        }
    }

    public static void throwIfFalse(boolean expression,String errorMsg){
        if (!expression){
            throw new ApiAlterException(errorMsg);
        }
    }

    public static void throwIfTrue(boolean expression, String errorMessage) {
        if (expression) {
            throw new ApiAlterException(errorMessage);
        }
    }
}
